package com.ycg.vue.modules.user.controller;

import com.ycg.vue.Entity.UserEntity;
import com.ycg.vue.Entity.Dto.UserDto;
import com.ycg.vue.modules.admin.controller.UserManageController;
import com.ycg.vue.modules.admin.service.UserManageService;
import com.ycg.vue.result.Result;
import com.ycg.vue.modules.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Description 用户管理
 * @Author jink
 * @Date 2024/1/5
 */
@Slf4j
@RestController
@RequestMapping("/user")
@Api(tags = "用户管理")
public class UserController {

    @Resource
    private UserService userService;

    @Resource
    private UserManageService userManageService;
    @Autowired
    private UserManageController userManageController;

    @ApiOperation(value = "用户登录")
    @PostMapping("/login")
    public Result user(@RequestBody UserDto userDto, HttpServletRequest request) {
        return userService.login(userDto,request);
    }

    @ApiOperation(value = "用户注册")
    @PostMapping("/register")
    public Result register(@RequestBody UserDto user) {
        return userService.register(user);
    }

    @ApiOperation(value = "头像上传")
    @RequestMapping("/register/avatar")
    public Result upload(@RequestParam("file") MultipartFile file) {
        return userService.upload(file);
    }

    @RequestMapping("/updateHeadImage")
    public Result updateHeadImage(@RequestParam("file") MultipartFile file) {
        return userService.updateHeadImage(file);
    }

    @RequestMapping("/getUser")
    public Result getUser() {
        return userService.getUser();
    }

    @PostMapping("/updateUser")
    public Result updateUser(@RequestBody UserEntity user) {
        return userManageController.updateUser(user);
    }

    @PostMapping("/updatePassword")
    public Result updatePassword(@RequestBody Map<String,String> pwd) {
        return userService.updatePassword(pwd);
    }

    @PostMapping("/updateHeadImgByMaterial")
    public Result updateHeadImgByMaterial(@RequestBody Map<String,String> map) {
        return userService.updateHeadImgByMaterial(map);
    }

}
